package com.zzf.concurrent.example.design.pattern.customer.producer;

import com.zzf.concurrent.example.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author GaoFeng2017
 * @date 2019/9/9 16:31
 */
@Slf4j
public class CustomerWorker extends Thread {

    private MessageQueue<String> messageQueue;

    public CustomerWorker(MessageQueue<String> messageQueue) {
        this.messageQueue = messageQueue;
    }

    @Override
    public void run() {
        while (true) {
            String message = messageQueue.poll();
            log.info("Customer consume message -> {}", message);
            TimeUtil.sleep((long) (Math.random() * 2000));
        }
    }
}
